////获附件数量
	var quoteId=jQuery("#id").val();
	var numId='quoteANum';
	if(quoteId!=''){
		showANum(quoteId,'普通价格单附件',numId);
	}
//选择审批级数时的变化
jQuery('#auditorNumber').change(function() {
	var n = jQuery(this).val();
	jQuery("input[name*='ai']").each(function() {
		var index = jQuery(this).prop('id').substr(-1);
		var parent = jQuery(this).parent().parent();
		if (index > n)
			parent.addClass('hide');
		else
			parent.removeClass('hide');
	});
});
// 投标提交审批
jQuery(".app-btn-submit")
		.on(
				'click',
				function() {
					var name = jQuery("#name").val();
					var num = jQuery("#auditorNumber").val();
					for(var i=1;i<=num;i++){
						var val= jQuery("#ai"+i).val();
						if(!val){
							message('审批人没有指定！');
							return;
						}
					}
			
					$.springLemonDialog({
						content : '确认提交审批：' + quoteName + '？',// 确认文本
						clickButton : function(sender, modal, index) {// 按钮事件处理
							// index:0 确认 1：取消
							// sender:事件源 如按钮，sender.html()可得到按钮文字如：取消
							if (index == 0) {
								 var d2={
					 						"isNewProduct":jQuery("#isNewProduct").val()
					 				};
					 				var url2 = window.rootPath + '/api/quotes/' + quoteId;
					 				jQuery.ajax({
					 					url : encodeURI(url2),
					 					type : 'patch',
					 					data : JSON.stringify(d2),
					 					dataType : 'json',
					 					contentType : 'application/json;charset=utf-8',
					 					success : function() {
					 						var url = window.rootPath + "/ui/quote/audit/"
											+ quoteId+"?name="+name;
									jQuery.post(encodeURI(url), jQuery('#form-quote').serialize(), function(data) {

										if (data.code == 0) {
											window.location = window.rootPath
													+ "/ui/quote/";
										}
									});
					 					}
					 				});
								
								

							}
							$(this).closeDialog(modal);
						}
					});

				});

// 引入客户信息弹窗
jQuery('.btn-find-auditor').on("click", function() {
	currentAuditor = jQuery(this).prop('id');
	jQuery("#modal-find-auditor").modal('show');
	jQuery("#modal-find-auditor input[type='radio']").attr('checked', false);
});

// 查询
jQuery('#app-btn-search').on('click', function() {
	var key = jQuery("#search").val();
	serverUserData.key = key;
	serverUserTable.draw();
});
// 撤销查询
jQuery('.app-btn-reset').on('click', function() {
	jQuery('#search').val('');
	serverUserData.key = '';
	serverUserTable.draw();
});

// 用户信息加载
var serverUserData = {};
serverUserData.key = '';
serverUserTable = jQuery('#table-user')
		.DataTable(
				{
					"serverSide" : true,
					"iDisplayLength" : 4,
					"ordering" : false,
					"ajax" : {
						"dataType" : "json",
						"type" : "get",
						"cache" : false,
						"url" : window.rootPath + '/ui/user/getpage',
						"data" : function(d) {
							return $.extend({}, d, serverUserData);
						}
					},
					columns : [
							{
								// 1序号
								data : null,
								defaultContent : ""
							},
							{// 2姓名
								data : "empLogin.name",
							},
							{// 3性别
								data : 'sex'
							},

							{// 4职务
								data : 'position'
							},
							{// 5销售区域
								data : 'saleArea.areaName'
							},
							{// 6选择按钮
								data : null,
								render : function() {
									var html = "<input type='radio' name='btn-select' class='app-select-user'/>"
									return html;
								}
							}

					],
					"drawCallback" : function(oSettings) {
						var k = 0;
						var total = oSettings.aiDisplay.length
								+ oSettings._iDisplayStart;

						for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
							$(
									'td:eq(0)',
									oSettings.aoData[oSettings.aiDisplay[k]].nTr)
									.text(i + 1);
							k++;
						}

						serverUserTable.off('click', 'tr');
						serverUserTable
								.on(
										'click',
										'tr',
										function(event) {
											event = event || window.event;
											var target = event.target
													|| event.scrElement;
											var data = serverUserTable
													.row(this).data();

											if (target.className
													.indexOf('app-select-user') != -1) {
												onSelectUser(data);
											}
											return;
										});
					}
				});// end of datatable
var selectedUser = null;
var currentAuditor = null;
var onSelectUser = function onSelectUser(data) {
	selectedUser = data;
};

// 引入用户按钮
jQuery('#btn-reference').on('click', function() {
	if (selectedUser && currentAuditor) {
		jQuery("#ai" + currentAuditor).val(selectedUser.empLogin.name);
		jQuery("#auditor" + currentAuditor).val(selectedUser.id);
	}

	selectedUser = null;
	currentAuditor = null;
	jQuery("#modal-find-auditor").modal('hide');
});
// 查找用户返回按钮
jQuery('.app-find-user-return').on('click', function() {
	selectedUser = null;
	currentAuditor = null;
});

// 泵table
var serverData = {};
serverData.quoteId = jQuery("#id").val();
var serverTable;
jQuery(document)
		.ready(
				function() {
					serverTable = jQuery('#mainDeviceTable')
							.DataTable(
									{
										"serverSide" : true,
										"ordering" : false,
										"ajax" : {
											"dataType" : "json",
											"type" : "get",
											"cache" : false,
											"url" : window.rootPath
													+ '/ui/quote/getDevicepage',
											"data" : function(d) {
												return $.extend({}, d,
														serverData);
											}
										},
										columns : [ {
											data : null,
											defaultContent : ""
										}, 
										{
											data : 'productName'
										}, 
										{
											data : 'productType'
										}, 
										{
											data : 'productModel'
										},
										{
											data : null,
											render : function(data,type, full, meta) {
												var dOut;
												if (data.isInventory == "1") {
													dOut = '<td class="center" ><span class="badge label-pill label-primary">降库产品</span></td>';
												} else if (data.isInventory == "2"){
													dOut = '<td class="center" ><span class="badge label-pill label-success">被降库</span></td>';
												}else{
													dOut = '<td class="center" ><span class="badge label-pill label-danger">未降库</span></td>';
												}
												return dOut;
											}
										},
										{
											data : 'number'
										},
										{
											data:'unit'
										}, 
										{
											data : 'costPrice'
										},
										{
											data : 'unitPrice'
										}, {
											data : 'power'
										}, {
											data : 'flowMaterial'
										}, {
											data : 'transMedia'
										}, {
											data : 'viscosity'
										}, {
											data : 'flux'
										}, {
											data : 'pumpLift'
										}, {
											data : 'temperature'
										}, {
											data : 'proportion'
										}, {
											data : 'inPressure'
										}, {
											data : 'effectiveNPSHA'
										}, {
											data : 'mustMPSHA'
										} ],
										"drawCallback" : function(oSettings) {
											var k = 0;
											var total = oSettings.aiDisplay.length
													+ oSettings._iDisplayStart;
											for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
												$(
														'td:eq(0)',
														oSettings.aoData[oSettings.aiDisplay[k]].nTr)
														.text(i + 1);
												k++;
											}

										}
									});
				});
// 其他table
var serverData1 = {};
var serverTable1;
serverData1.quoteId = jQuery("#id").val();
jQuery(document)
		.ready(
				function() {
					serverTable1 = jQuery('#otherTable')
							.DataTable(
									{
										"serverSide" : true,
										"ordering" : false,
										"ajax" : {
											"dataType" : "json",
											"type" : "get",
											"cache" : false,
											"url" : window.rootPath
													+ '/ui/quote/getOtherpage',
											"data" : function(d) {
												return $.extend({}, d,
														serverData1);
											}
										},
										columns : [ {
											data : null,
											defaultContent : ""
										}, {
											data : 'deviceName'
										}, {
											data : 'type'
										}, 
										{
											data : 'material'
										},
										{
											data : 'unit'
										}, {
											data : 'amount'
										},
										{
											data : 'costPrice'
										},
										{
											data : 'price'
										} ],
										"drawCallback" : function(oSettings) {
											var k = 0;
											var total = oSettings.aiDisplay.length
													+ oSettings._iDisplayStart;
											for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
												$(
														'td:eq(0)',
														oSettings.aoData[oSettings.aiDisplay[k]].nTr)
														.text(i + 1);
												k++;
											}
										}
									});

				});
// 下载附件
jQuery(".download").on('click', function() {
	var quoteId = jQuery("#id").val();
	filedown(quoteId, '普通价格单附件',1);
});
